package cn.kgc.springcloud.service;

import cn.kgc.springcloud.entity.Clazz;
import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.feignclient.TagClient;
import cn.kgc.springcloud.mapper.ClazzMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/6/16
 */
@Service
public class ClazzServiceImpl implements  ClazzService {
    @Autowired
    private ClazzMapper clazzMapper;
    @Autowired
    private TagClient tagClient;
    @Override
    public List<Clazz> getAll() {
        List<Clazz> clazzes = clazzMapper.selectAll();
        //遍历集合 根据班级中标签id 查询 标签对象
        clazzes.forEach(clazz -> {
            Integer tagId = clazz.getTagId();
            Tag tag = tagClient.getOneById(tagId);
            clazz.setTag(tag);
        }) ;
        return clazzes;
    }

    @Override
    public Clazz addClazz(Clazz clazz) {
        Integer integer = clazzMapper.addClazz(clazz);
        return clazz;
    }

    @Override
    public void deleteClazz(Integer id) {

        Integer integer = clazzMapper.deleteById(id);

    }

    @Override
    public Clazz getById(Integer id) {
        return clazzMapper.selectById(id);
    }
}
